<?php

namespace Platform\Models\Report;

use Platform\Models\BaseModel;

class Report extends BaseModel {

    private $id;
    private $objectId;     //数据类型id
    private $objectType;   //举报类型（1.为评论举报）
    private $beReportUserId;     //被举报用户id
    private $beReportUserName;     //被举报用户昵称
    private $userId;       //举报用户id
    private $userName;     //举报用户昵称
    private $createTime;   //创建时间
    private $isDel;        //是否删除
    private $content;      //举报内容
    private $handleStatus;   //被评论的内容
    private $handleResult; //被评论的数量
    private $handleUserId;    //点赞次数
    private $handleTime;      //父评论id

    public function getId() {
        return $this->id;
    }

    public function getObjectId() {
        return $this->objectId;
    }

    public function getObjectType() {
        return $this->objectType;
    }

    public function getBeReportUserId() {
        return $this->beReportUserId;
    }

    public function getBeReportUserName() {
        return $this->beReportUserName;
    }

    public function getUserId() {
        return $this->userId;
    }

    public function getUserName() {
        return $this->userName;
    }

    public function getCreateTime() {
        return $this->createTime;
    }

    public function getIsDel() {
        return $this->isDel;
    }

    public function getContent() {
        return $this->content;
    }

    public function getHandleStatus() {
        return $this->handleStatus;
    }

    public function getHandleResult() {
        return $this->handleResult;
    }

    public function getHandleUserId() {
        return $this->handleUserId;
    }

    public function getHandleTime() {
        return $this->handleTime;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function setObjectId($objectId) {
        $this->objectId = $objectId;
    }

    public function setObjectType($objectType) {
        $this->objectType = $objectType;
    }

    public function setBeReportUserId($beReportUserId) {
        $this->beReportUserId = $beReportUserId;
    }

    public function setBeReportUserName($beReportUserName) {
        $this->beReportUserName = $beReportUserName;
    }

    public function setUserId($userId) {
        $this->userId = $userId;
    }

    public function setUserName($userName) {
        $this->userName = $userName;
    }

    public function setCreateTime($createTime) {
        $this->createTime = $createTime;
    }

    public function setIsDel($isDel) {
        $this->isDel = $isDel;
    }

    public function setContent($content) {
        $this->content = $content;
    }

    public function setHandleStatus($handleStatus) {
        $this->handleStatus = $handleStatus;
    }

    public function setHandleResult($handleResult) {
        $this->handleResult = $handleResult;
    }

    public function setHandleUserId($handleUserId) {
        $this->handleUserId = $handleUserId;
    }

    public function setHandleTime($handleTime) {
        $this->handleTime = $handleTime;
    }

    public function initialize() {
        parent::initialize();
        $this->setSource("report");
    }

    public function getSource() {
        return 'report';
    }

    public function columnMap() {
        //列名 =》 属性名
        return [
            'id' => 'id',
            'object_id' => 'objectId',
            'object_type' => 'objectType',
            'user_id' => 'userId',
            'be_report_user_id' => 'beReportUserId',
            'be_report_user_name' => 'beReportUserName',
            'user_name' => 'userName',
            'create_time' => 'createTime',
            'is_del' => 'isDel',
            'content' => 'content',
            'handle_status' => 'handleStatus',
            'handle_result' => 'handleResult',
            'handle_user_id' => 'handleUserId',
            'handle_time' => 'handleTime'
        ];
    }

    /*
     * 查询举报信息
     */

    public function checkIsReportObject($userId, $objectId, $objectType) {
        $reportInfo = parent::findFirst([
                    'conditions' => 'userId = :userId: and objectId =  :objectId: and objectType = :objectType: and handleStatus = :handleStatus:',
                    'bind' => [
                        'userId' => $userId,
                        'objectId' => $objectId,
                        'objectType' => $objectType,
                        'handleStatus' => REPORT_STATUS['APPLY'],
                    ],
        ]);
        if ($reportInfo) {
            $reportInfo = $reportInfo->toArray();
        }
        return $reportInfo;
    }

    /**
     * 更新举报状态
     * @param type $idArr
     * @param type $status
     * @param type $adminId
     * @return type
     */
    public function updateStatusByIds($idArr, $status, $adminId) {
        $phql = "UPDATE " . __CLASS__ . " SET handleStatus = " . $status . ",handleUserId = " . $adminId . " ,handleTime = " . time() . " WHERE id IN ({id:array}) ";
        $result = $this->getModelsManager()->executeQuery($phql, array(
            'id' => $idArr
        ));
        if (!$result) {
            E('更新失败');
        }
        return $result;
    }

}
